FROM golang:1.20-alpine3.18 as builder

ENV GOPROXY https://goproxy.cn
WORKDIR /src
COPY . .
#COPY go.sum go.sum
RUN go mod tidy
RUN go mod download

# Copy the go source for building server

# Build
RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux go build -a -o mayfly-go main.go

FROM alpine:3.18
# 设定时区
ENV TZ=Asia/Shanghai
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk add tzdata && cp /usr/share/zoneinfo/${TZ} /etc/localtime \
    && echo ${TZ} > /etc/timezone 

RUN apk add --no-cache ca-certificates bash expat

WORKDIR /mayfly

COPY --from=builder /src/run.sh /src/run.sh
COPY --from=builder /src/config.yml /src/config.yml
COPY --from=builder /src/config.yml /mayfly/config.yml
COPY --from=builder /src/mayfly-go /usr/local/bin/mayfly-go

CMD ["bash","/src/run.sh"]
